package com.yonyou.wdt.service;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.yonyou.wdt.entity.OpenApiURLEnum;
import com.yonyou.wdt.entity.QueryDto;
import com.yonyou.wdt.utils.RequestTool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@Component
public class YonsuiteService extends BaseApi {

    private static final Logger logger = LoggerFactory.getLogger(YonsuiteService.class);
    /*
   客户列表查询
   */
    public JSONObject getMerchantList(Map<String, Object> params, QueryDto dto) throws Exception {
        String data = doPost(dto.getGatewayUrl() + OpenApiURLEnum.MERCHANT_LIST, params, dto);
        return JSONUtil.parseObj(data);
    }
    /*
   采购订单列表查询
   */
    public JSONObject purOrderList(Map<String, Object> params, QueryDto dto) throws Exception {
        String data = doPost(dto.getGatewayUrl() + OpenApiURLEnum.PUR_ORDER_LIST, params, dto);
        return JSONUtil.parseObj(data);
    }
    /**
     * @Author Huangwb
     * @Description 获取租户动态域名
     * @Date 11:13 2023/8/22
     **/
    public JSONObject getDynamicDomainName(HashMap<String, Object> params, String tenantId) throws Exception {
        return JSONUtil.parseObj(getRequestData1(RequestTool.doGet("https://apigateway.yonyoucloud.com/open-auth/dataCenter/getGatewayAddress?tenantId=" + tenantId, params, false)));
    }

    /**
     * @Author Huangwb
     * @Description 价格表查询 - 系统接口
     * @Date 2024/4/7 16:50
     **/
    public JSONObject priceListQuery(Map<String, Object> params, QueryDto dto) throws Exception {
        String data = doPost(dto.getGatewayUrl() + OpenApiURLEnum.PRICING_LIST, params, dto);
        return JSONUtil.parseObj(data);
    }

    /**
     * @Author Huangwb
     * @Description 查询Ys客户组织映射关系表
     * @Date 2023/11/8 11:55
     **/
    public JSONObject shopOrgMapQuery(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + "/" + dto.getTenantId() + OpenApiURLEnum.SHOPORGMAPQUERY_LIST, params, dto));
    }

    public JSONObject shopOrgQuery(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + "/" + dto.getTenantId() + OpenApiURLEnum.SHOPORGQUERY_LIST, params, dto));
    }

    public JSONObject saleReturnSave(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + OpenApiURLEnum.SALERETURN_SAVE, params, dto));
    }
    public JSONObject saleOutMergeSave(Map<String, Object> params, QueryDto queryDto) throws Exception {
        String data = doPost(queryDto.getGatewayUrl() +OpenApiURLEnum.SALE_STOCK_OUT_MERGE_SOURCE_SAVE, params, queryDto);
        return JSONUtil.parseObj(data);
    }
    public JSONObject otherInSave(Map<String, Object> params, QueryDto queryDto) throws Exception {
        String data = doPost(queryDto.getGatewayUrl() +OpenApiURLEnum.OTHINRECORD_SAVE, params, queryDto);
        return JSONUtil.parseObj(data);
    }
    public JSONObject saleReturnList(Map<String, Object> params, QueryDto queryDto) throws Exception {
        String data = doPost(queryDto.getGatewayUrl() +OpenApiURLEnum.SALE_STOCK_RETURN_QUERY, params, queryDto);
        return JSONUtil.parseObj(data);
    }
    public JSONObject otherInList(Map<String, Object> params, QueryDto queryDto) throws Exception {
        String data = doPost(queryDto.getGatewayUrl() +OpenApiURLEnum.OTHER_IN_LIST_QUERY, params, queryDto);
        return JSONUtil.parseObj(data);
    }
    public JSONObject otherOutList(Map<String, Object> params, QueryDto queryDto) throws Exception {
        String data = doPost(queryDto.getGatewayUrl() +OpenApiURLEnum.OTHER_OUT_LIST_QUERY, params, queryDto);
        return JSONUtil.parseObj(data);
    }
    public JSONObject transferOutList(Map<String, Object> params, QueryDto queryDto) throws Exception {
        String data = doPost(queryDto.getGatewayUrl() +OpenApiURLEnum.TRANSFER_OUTWARE_LIST_QUERY, params, queryDto);
        return JSONUtil.parseObj(data);
    }
    public JSONObject applySave(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + OpenApiURLEnum.APPLY_SAVE, params, dto));
    }

    public JSONObject receivableSace(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + OpenApiURLEnum.RECEIVABLE_SAVE, params, dto));
    }

    public JSONObject bomSave(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + OpenApiURLEnum.BOM_SAVE, params, dto));
    }

    public JSONObject bomAudit(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + OpenApiURLEnum.BOM_AUDIT, params, dto));
    }
    public JSONObject checkDiffList(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + OpenApiURLEnum.CHECK_DIFF_LIST_QUERY, params, dto));
    }
    public JSONObject transferOrderList(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + OpenApiURLEnum.TRANSFER_ORDER_LIST_QUERY, params, dto));
    }
    public JSONObject transferOutSave(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + OpenApiURLEnum.TRANSFER_OUT_SAVE, params, dto));
    }
    public JSONObject transferInSave(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + OpenApiURLEnum.TRANSFER_IN_SAVE, params, dto));
    }
    public JSONObject warehouseQuery(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + OpenApiURLEnum.WAREHOUSE_LIST, params, dto));
    }
    public JSONObject custDocQuery(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + OpenApiURLEnum.CUST_DOC_LIST_QUERY, params, dto));
    }
    public JSONObject storeTransferSave(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + OpenApiURLEnum.STORE_TRANSFER_SAVE, params, dto));
    }

    public JSONObject saleOrderSave(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + OpenApiURLEnum.SALES_ORDER_SAVE, params, dto));
    }
    public JSONObject saleOrderList(Map<String, Object> params, QueryDto dto) throws Exception {
        return JSONUtil.parseObj(doPost(dto.getGatewayUrl() + OpenApiURLEnum.SALES_ORDER_LIST, params, dto));
    }

    public JSONObject ysProductQuery(Map<String, Object> params, QueryDto dto) throws Exception {
        String data = doPost(dto.getGatewayUrl() + OpenApiURLEnum.PRODUCT_FEATURE_LIST, params, dto);
        JSONObject json = JSONUtil.parseObj(data);
        return json;
    }

    public JSONObject ysProductDetailQuery(Map<String, Object> params, QueryDto dto) throws Exception {
        String data = doPost(dto.getGatewayUrl() + OpenApiURLEnum.PRODUCT_DTL_QUERY, params, dto);
        JSONObject json = JSONUtil.parseObj(data);
        return json;
    }

    public JSONObject ysTaxQuery(Map<String, Object> params, QueryDto dto) throws Exception {
        String data = doGet(dto.getGatewayUrl() + OpenApiURLEnum.TAX_DTL_QUERY, params, dto);
        JSONObject json = JSONUtil.parseObj(data);
        return json;
    }

    public JSONObject ysTaxListQuery(Map<String, Object> params, QueryDto dto) throws Exception {
        String data = doPost(dto.getGatewayUrl() + OpenApiURLEnum.TAX_LIST_QUERY, params, dto);
        JSONObject json = JSONUtil.parseObj(data);
        return json;
    }

    public JSONObject ysPriceListQuery(Map<String, Object> params, QueryDto dto) throws Exception {
        String data = doPost(dto.getGatewayUrl() + OpenApiURLEnum.PRICE_LIST_QUERY, params, dto);
        JSONObject json = JSONUtil.parseObj(data);
        return json;
    }

    public JSONObject ysBomListQuery(Map<String, Object> params, QueryDto dto) throws Exception {
        String data = doPost(dto.getGatewayUrl() + OpenApiURLEnum.BOM_LIST_QUERY, params, dto);
        JSONObject json = JSONUtil.parseObj(data);
        return json;
    }

    public JSONObject ysBomDetailQuery(Map<String, Object> params, QueryDto dto) throws Exception {
        String data = doPost(dto.getGatewayUrl() + OpenApiURLEnum.BOM_DETAIL_QUERY, params, dto);
        JSONObject json = JSONUtil.parseObj(data);
        return json;
    }

    public JSONObject postProductSave(JSONObject params, QueryDto dto) throws Exception {
        String data = doPost(dto.getGatewayUrl() + OpenApiURLEnum.PRODUCT_NEW_SAVE, params, dto);
        JSONObject json = JSONUtil.parseObj(data);
        return json;
    }

    public JSONObject purchaseInSave(Map<String, Object> params, QueryDto dto) throws Exception {
        String data = doPost(dto.getGatewayUrl() + OpenApiURLEnum.PURCHASE_IN_SAVE, params, dto);
        JSONObject json = JSONUtil.parseObj(data);
        return json;
    } public JSONObject purchaseInMerge(Map<String, Object> params, QueryDto dto) throws Exception {
        String data = doPost(dto.getGatewayUrl() + OpenApiURLEnum.PURINRECORD_IN_SAVE, params, dto);
        JSONObject json = JSONUtil.parseObj(data);
        return json;
    }

    public JSONObject ysProductDetailNewQuery(ArrayList<Map<String, Object>> mapList, QueryDto dto) throws Exception {
        String data = doPost(dto.getGatewayUrl() + OpenApiURLEnum.PRODUCT_LIST_BATCHDETAILNEW, mapList, dto);
        return JSONUtil.parseObj(data);
    }
}
